package com.example.shopping.controller;

import com.example.shopping.pojo.Seller;
import com.example.shopping.service.SellerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.Id;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/*
Create by 苍狼 于 2020/1/16
站在巅峰看世界，
落在深渊思人生。
*/
@CrossOrigin
@Controller
//商家审核
public class SellerReviewController {
    @Autowired(required = false)
    private SellerService sellerService;

    //全部查询
    @RequestMapping("/selectSellerListSellerReview")
    public String selectSellerList(HttpServletRequest request) {
        List<Seller> sellerList = sellerService.selectSellerList();
        request.getSession().setAttribute("sellerList", sellerList);
        return "sellerReview";
    }

    //根据商家名称和公司名称模糊查询
    @RequestMapping("/QueryByLikeSellerReview")
    public String QueryByLike(Seller seller, HttpServletRequest request) {
        if (seller != null && !seller.equals("")) {
            List<Seller> sellerList = sellerService.queryByLike(seller);
            request.getSession().setAttribute("sellerList", sellerList);
            return "seller";
        }
        return "redirect:/selectList";
    }

    //数据回显
    @RequestMapping("/selectSellerReviewListById")
    public String selectSellerListById(int id, HttpServletRequest request) {
        Seller seller = sellerService.SellerById(id);
        request.getSession().setAttribute("seller", seller);
        return "updateSeller";
    }

    //修改
    @RequestMapping("/updateSellerReview")
    public String update(Seller seller) {
        int i = sellerService.update(seller);
        if (i > 0) {
            return "redirect:selectSellerList";
        }
        return "redirect:update";
    }

    //关闭商家店铺
    @RequestMapping("/updateCloseSellerReview")
    public String updateCloseSeller(int id) {
        sellerService.updateCloseSeller(id);
        return "redirect:selectSellerList";
    }


    //审核状态通过
    @RequestMapping("/updateStatusYesSellerReview")
    public String updateStatusYes(int id) {
        sellerService.updateStatusYes(id);
        return "redirect:selectSellerList";
    }

    //审核状态未通过
    @RequestMapping("/updateStatusNoSellerReview")
    public String updateStatusNo(int id) {
        sellerService.updateStatusNo(id);
        return "redirect:selectSellerList";
    }
}
